package com.qyhl.webtv.module_live.teletext.detail.popview;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.live.ShoppingListBean;
import com.qyhl.webtv.module_live.common.LiveUrl;

import java.util.List;

public class TeleTextShopModel implements TeleTextShopContract.TeleTextShopModel {
    private TeleTextShopPresenter mPresenter;

    public TeleTextShopModel(TeleTextShopPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getShopList(String sceneId, String page) {
        EasyHttp.get(LiveUrl.GET_TELETEXT_SHOP_LIST)
                .params("scentId", sceneId)
                .params("page", page)
                .execute(new SimpleCallBack<List<ShoppingListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<ShoppingListBean> beanList) {
                        if (beanList != null && beanList.size() > 0) {
                            mPresenter.setList(beanList, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }
}
